#include "ConversionTool.h"

int stringToInt(string str) 
{
	int result;
	try
	{
		std::stringstream myStream(str);
		myStream >> result;
	}
	catch ( ... )
	{
		cout << "Convert::stringToInt> Conversion failed because of bad input format." << endl;
	}
	return result;
}

string intToString(int i)
{
	ostringstream s;
	try
	{
		s<<i;
	}
		catch ( ... )
	{
			cout << "Convert::intToString> Conversion failed because of bad input format." << endl;
	}
	return s.str();
}

double stringToDouble(string str) 
{
	double result;
	try
	{
		std::stringstream myStream(str);
		myStream >> result;
	}
	catch ( ... )
	{
		cout << "Convert::stringToDouble> Conversion failed because of bad input format." << endl;
	}
	return result;
}

string doubleToString(double d)
{
	ostringstream s;
	try 
	{
		s.setf( ios::fixed, ios::floatfield );
		s.precision(15);
		s << d;
	}
	catch ( ... )
	{
		cout << "Convert::doubleToString> Conversion failed because of bad input format." << endl;
	}
	return s.str();
}

float stringToFloat(string str) 
{
	float result;
	try
	{
		std::stringstream myStream(str);
		myStream >> result;
	}
	catch ( ... )
	{
		cout << "Convert::stringToFloat> Conversion failed because of bad input format." << endl;
	}
	return result;
}

string floatToString(float d)
{
	ostringstream s;
	try 
	{
		s.setf( ios::fixed, ios::floatfield );
		s.precision(15);
		s << d;
	}
	catch ( ... )
	{
		cout << "Convert::floatToString> Conversion failed because of bad input format." << endl;
	}
	return s.str();
}
